#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
using namespace std;
int read(){
    int x=0,f=1;
    char c='\0';
    while(c!='-'&&(c<'0'||c>'9'))c=getchar();
    while(c=='-'){f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int T,n,m,L,V,d[100010],v[100010],a[100010],p[100010],sum,sav[100010],tmp,tp,del;
int Find(int N,bool P){
    if(N<p[0])return P?-1:(m-1);
    if(N>p[m-1])return P?(m-1):-1;
    int l=0,r=m-1,mid;
    while(r>l){
        mid=(r+l)>>1;
        if(l>=r)break;
        else if(p[mid]>N)r=mid-1;
        else if(p[mid+1]<N)l=mid+1;
        else break;
    }
    return mid;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    T=read();
    while(T--){
        n=read();m=read();L=read();V=read();
        f(i,n){
            d[i]=read();
            v[i]=read();
            a[i]=read();
        }
        f(i,m)p[i]=read();
        sort(p,p+m);
        f(i,n){
            if(d[i]>p[m-1])continue;
            if(a[i]<0){
                tp=Find(d[i],1);
                if(v[i]*v[i]+2*a[i]*(p[tp+1]-d[i])>V*V){
                    sav[tp+1]=1;
                    tmp=Find(((V*V-v[i]*v[i])/a[i])>>1+d[i],0);
                    if(tmp>tp)sav[tmp+1]=-1;
                    else sav[tp+1]=0;
                    sum++;
                }
            }
            else if(a[i]>0&&v[i]*v[i]+2*a[i]*(p[m-1]-d[i]>V*V)){
                sav[m-1]=1;
                sum++;
            }
        }
        for(int i=1;i<=m;i++){
            sav[i]+=sav[i-1];
            if(sav[i]<sav[i-1])del+=sav[i-1]-1;
        }
        printf("%d %d\n",sum,m-sum+del);
        memset(sav,sizeof(sav),0);
        sum=del=tmp=0;
    }
    return 0;
}
